package com.chinasolf.yygh.user.controller;


import com.chinasoft.model.user.UserInfo;
import com.chinasoft.vo.user.LoginVo;
import com.chinasoft.vo.user.UserAuthVo;
import com.chinasolf.result.R;
import com.chinasolf.utils.AuthHeaderVaueUtils;
import com.chinasolf.yygh.user.service.UserInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2022-03-24
 */
@RestController
@RequestMapping("/api/user")
public class UserInfoController {
    @Autowired
    private UserInfoService userInfoService;

    //用户登录的方法（手机验证码）
    @ApiOperation("用户登录的方法")
    @PostMapping("login")
    public R login(@RequestBody LoginVo loginVo){
        Map<String,Object> map = userInfoService.loginUser(loginVo);
        return R.ok().data(map);
    }
    //用户认证接口
    @PostMapping("auth/userAuth")
    public R userAuth(@RequestBody UserAuthVo userAuthVo,
                        HttpServletRequest Request){
        Long userId = AuthHeaderVaueUtils.getUserIdByHeader(Request);
        userInfoService.userAuth(userId,userAuthVo);

        return R.ok();
    }
    //获取用户id信息接口
    @GetMapping("auth/getUserInfo")
    public R getUserInfo(HttpServletRequest request) {
        Long userId = AuthHeaderVaueUtils.getUserIdByHeader(request);
        UserInfo userInfo = userInfoService.getById(userId);
        return R.ok().data("userInfo",userInfo);
    }





}

